﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MediaBot.Library
{
    public class ConfigurationSettings
    {
        public const int CONFIGURATION_SETTINGS_REQUESTTIMEOUT = 60;
        public const int CONFIGURATION_SETTINGS_RETRY = 5;
        public const int CONFIGURATION_SETTINGS_DOWNLOADINTERVAL = 30;
        public const int CONFIGURATION_SETTINGS_NUMBEROFTHREADS = 6;
        public const string CONFIGURATION_SETTINGS_CONFIG_FOLDER = "Config";
        private static ConfigurationSettings _settings = new ConfigurationSettings();

        private ConfigurationSettings()
        {
            //requestTimeout
            string requestTimeout = System.Configuration.ConfigurationManager.AppSettings["RequestTimeout"];
            this.RequestTimeout = string.IsNullOrEmpty(requestTimeout)? CONFIGURATION_SETTINGS_REQUESTTIMEOUT : int.Parse(requestTimeout);

            //retry
            string retry = System.Configuration.ConfigurationManager.AppSettings["Retry"];
            this.Retry = string.IsNullOrEmpty(retry) ? CONFIGURATION_SETTINGS_RETRY : int.Parse(retry);

            //folder to store all download pages 
            this.FileDownloadFolder = System.Configuration.ConfigurationManager.AppSettings["FileDownloadFolder"];

            //interval between 2 downloads
            string downloadInterval = System.Configuration.ConfigurationManager.AppSettings["DownloadInterval"];
            this.DownloadInterval = string.IsNullOrEmpty(downloadInterval) ? CONFIGURATION_SETTINGS_DOWNLOADINTERVAL : int.Parse(downloadInterval);

            //interval between 2 downloads
            string fromDateString = System.Configuration.ConfigurationManager.AppSettings["FromDate"];
            this.FromDate = string.IsNullOrEmpty(fromDateString) ? DateTime.MinValue : DateTime.Parse(fromDateString);

            //number of threads in pool
            string numberOfThreads = System.Configuration.ConfigurationManager.AppSettings["NumberOfThreadsInPool"];
            this.NumberOfThreadsInPool = string.IsNullOrEmpty(numberOfThreads) ? CONFIGURATION_SETTINGS_NUMBEROFTHREADS : int.Parse(numberOfThreads);

            //facebook access token
            this.FacebookAccessToken = System.Configuration.ConfigurationManager.AppSettings["FacebookAccessToken"];

            this.YouTubeDeveloperKey = System.Configuration.ConfigurationManager.AppSettings["YouTubeDeveloperKey"];

            string isRunParallelString = System.Configuration.ConfigurationManager.AppSettings["IsRunParallelOnSite"];
            this.IsRunParallelOnSite = string.IsNullOrEmpty(isRunParallelString) ? true : bool.Parse(isRunParallelString);
            
        }

        public static ConfigurationSettings Settings
        {
            get
            {
                return _settings;
            }
        }

        public int RequestTimeout{ get; private set;}

        public int Retry{ get; private set;}

        public string FileDownloadFolder { get; private set; }

        public int DownloadInterval { get; private set; }

        public bool IsRunParallelOnSite { get; private set; }

        public int NumberOfThreadsInPool { get; private set; }

        public DateTime FromDate { get; private set; }

        public Guid SiteGUID
        {
            get
            {
                return Guid.Parse(System.Configuration.ConfigurationManager.AppSettings["SiteGUID"]);
            }
        }

        public string FacebookAccessToken { get; private set; }

        public string YouTubeDeveloperKey { get; private set; }

    }
}
